In [ ]:
import numpy as np
from bqplot import *
In [ ]:
np.random.seed(0)
size = 100
x_data = range(size)
y_data = np.cumsum(np.random.randn(size) * 100.0)
y_data_2 = np.cumsum(np.random.randn(size))
In [ ]:
y_sc = LinearScale()
ax_x = Axis(label='Test X', scale=y_sc, grid_lines='solid')
ax_y = Axis(label='Test Y', scale=y_sc, orientation='vertical', tick_format='0.2f')
line = Lines(x=y_data_2, y=y_data_2,
scales={'x': y_sc, 'y': y_sc}, colors=['hotpink', 'orange'])
m_fig = dict(left=100, top=50, bottom=50, right=100)
fig = Figure(axes=[ax_x, ax_y], marks=[line], fig_margin=m_fig)
fig
In [ ]:
# Displaying Grid Lines for the axis
ax_x.grid_lines = 'solid'
ax_y.grid_lines = 'dashed'
In [ ]:
# Changing the side of the axis
ax_y.side = "right"
ax_x.side = "top"
In [ ]:
ax_y.orientation = "horizontal"
ax_x.orientation = "vertical"
In [ ]:
## Changing the format of the ticks on the axis
fig.axes[0].tick_format = "0.2f"
fig.axes[1].tick_format = "0.0f"
In [ ]:
## Changing the color of the axis
with ax_x.hold_sync():
ax_x.color = 'orangered'
ax_x.label_color = 'orangered'
In [ ]:
#change the grid colors
ax_x.grid_color = 'red'
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
ax_x = Axis(label='Test X', scale=x_sc)
ax_y = Axis(label='Test Y', scale=y_sc, orientation='vertical', tick_format='0.3f')
line = Lines(x=x_data, y=y_data_2, scales={'x': x_sc, 'y': y_sc}, colors=['hotpink', 'orange'])
m_fig = dict(left=100, top=50, bottom=50, right=100)
Figure(axes=[ax_x, ax_y], marks=[line], fig_margin=m_fig)
In [ ]:
## moving the label along the axis
ax_x.label_location = 'end'
ax_y.label_location = 'start'
In [ ]:
## moving the label perpendicular to the axis
ax_y.label_offset = '6ex'
ax_x.label_offset = '-1em'
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
ax_x = Axis(label='index', scale=x_sc)
ax_y = Axis(label='Brownian', scale=y_sc, orientation='vertical', tick_format='0.2f')
line = Lines(x=x_data[:20], y=y_data[:20], scales={'x': x_sc, 'y': y_sc}, colors=['hotpink', 'orange'])
m_fig = dict(left=50, top=50, bottom=50, right=50)
Figure(axes=[ax_x, ax_y], marks=[line], fig_margin=m_fig)
In [ ]:
# Setting the number of ticks
ax_x.num_ticks = 8
In [ ]:
# Setting the tick values
ax_x.tick_values = np.arange(1, 21)
In [ ]:
# Setting the style for the text of the ticks
ax_x.tick_style={'stroke': 'orangered', 'font-size': 14}
In [ ]:
sc_x = LinearScale()
sc_y = LinearScale(reverse=True)
sc_y2 = LinearScale()
sc1 = Scatter(x=x_data[:10], y=y_data[:10],
scales={'x': sc_x, 'y': sc_y},
labels=['Test 1'],
default_size=100, display_legend=True)
sc2 = Scatter(x=x_data[:10], y=y_data_2[:10],
colors=['dodgerblue'],
marker='cross', labels=['Test 2'],
scales={'x': sc_x, 'y': sc_y2}, display_legend=True)
In [ ]:
## Setting offset for axis in terms of figure scales
ax_x = Axis(label='Test X', scale=sc_x,
grid_lines='solid', offset=dict(value=0.2), label_location="start")
ax_y = Axis(label='Test Y', scale=sc_y,
orientation='vertical', tick_format='0.2f', grid_lines='solid', label_location="end")
ax_y2 = Axis(label='Test Y2', scale=sc_y2, orientation='vertical', side='right',
tick_format='0.2f')
Figure(axes=[ax_x, ax_y, ax_y2], marks=[sc1, sc2], legend_location='top-right',
padding_x=0.025)
In [ ]:
# restoring to default position
ax_x.offset = {}
In [ ]:
ax_y.offset = dict(value=3.0, scale=sc_x)
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
col_sc = ColorScale()
scatter = Scatter(x=x_data, y=y_data, color=y_data_2,
scales={'x': x_sc, 'y':y_sc, 'color': col_sc})
ax_x = Axis(scale=x_sc)
ax_y = Axis(scale=y_sc, orientation='vertical', tick_format='0.2f')
ax_c = ColorAxis(scale=col_sc, label='Color')
margin=dict(top=80, left=80, right=80, bottom=80)
Figure(marks=[scatter], axes=[ax_x, ax_y, ax_c], fig_margin=margin)
In [ ]:
ax_c.side = 'top'
In [ ]:
with ax_c.hold_sync():
ax_c.orientation = 'vertical'
ax_c.side = 'right'
In [ ]:
ax_y.side = 'right'
ax_c.side = 'left'